import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: hp
 * Date: 2025-03-30
 * Time: 14:26
 */
public class RedisDemoList {
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
        /*try(Jedis jedis = jedisPool.getResource()) {
            System.out.println("lpush 和 lrange 的使用");
            jedis.flushAll();

            jedis.lpush("key1","111","222","333");

            List<String> result = jedis.lrange("key1",0,-1);
            System.out.println("result: " + result);
        }*/

        /*try(Jedis jedis = jedisPool.getResource()) {
            System.out.println("lpush 和 lrange 的使用");
            jedis.flushAll();

            jedis.rpush("key1","111","222","333");

            List<String> result = jedis.lrange("key1",0,-1);
            System.out.println("result: " + result);
        }
*/
        /*try(Jedis jedis = jedisPool.getResource()) {
            System.out.println("rpop 的使用");
            jedis.flushAll();

            jedis.rpush("key1","111","222","333");

            String result = jedis.rpop("key1");
            System.out.println("result: " + result);
            result = jedis.rpop("key1");
            System.out.println("result: " + result);
            result = jedis.rpop("key1");
            System.out.println("result: " + result);
            result = jedis.rpop("key1");
            System.out.println("result: " + result);
        }*/

        /*try(Jedis jedis = jedisPool.getResource()) {
            System.out.println("lpop的使用");
            jedis.flushAll();

            jedis.rpush("key1","111","222","333");

            String result = jedis.lpop("key1");
            System.out.println("result: " + result);
            result = jedis.lpop("key1");
            System.out.println("result: " + result);
            result = jedis.lpop("key1");
            System.out.println("result: " + result);
            result = jedis.lpop("key1");
            System.out.println("result: " + result);
        }*/


        /*try(Jedis jedis = jedisPool.getResource()) {
            System.out.println("brpop 的使用");
            jedis.flushAll();

            List<String> result = jedis.brpop(3,"key1");
            System.out.println("result[0]: " + result.get(0));
            System.out.println("result[1]: " + result.get(1));
        }*/



        try(Jedis jedis = jedisPool.getResource()) {
            System.out.println("rpop 的使用");
            jedis.flushAll();

            jedis.rpush("key1","111","222","333");

            long result = jedis.llen("key1");
            System.out.println("result: " + result);
        }

    }
}
